package com.xoa.dev.workFlow.controller;

import com.xoa.dev.workFlow.service.WorkFlowSelectBranchService;
import com.xoa.model.users.Users;
import com.xoa.util.AjaxJson;
import com.xoa.util.CookiesUtil;
import com.xoa.util.common.session.SessionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/WorkFlowSelectBranch")
public class WorkFlowSelectBranchController {

    @Autowired
    WorkFlowSelectBranchService workFlowSelectBranchService;


    @RequestMapping(value = "getBranch", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public AjaxJson getBranch(HttpServletRequest request,
                              @RequestParam Integer flowId,
                              @RequestParam Integer currentFlowPrcs,
                              @RequestParam Integer runId) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(), redisSessionCookie);
        return workFlowSelectBranchService.getBranch(flowId, currentFlowPrcs, runId, user);
    }




}
